package com.sven.zuulgateway.config2;

import com.netflix.zuul.FilterProcessor;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;

/**
 * 自定义的zuul过滤器的核心处理器
 */
public class DidiFilterProcessor extends FilterProcessor {
    @Override
    public Object processZuulFilter(ZuulFilter filter) throws ZuulException {
        System.out.println("----进入DidiFilterProcessor----processZuulFilter方法---"+filter);
        try {
            return super.processZuulFilter(filter);
        } catch (ZuulException e) {
            System.out.println("----DidiFilterProcessor----processZuulFilter----进入异常---"+filter);
            //向请求上下文中记录一些信息，以便在ErrorDealPostFilter中可以判断哪一种类型的过滤器
            RequestContext ctx = RequestContext.getCurrentContext();
            ctx.set("failed.filter", filter);
            throw e;
        }
    }
}
